package com.cidp.system.dao.impl;

import com.cidp.system.dao.IDictParamDao;
import com.cidp.system.model.TdictParam;
import com.cidp.system.pojo.DictParamPo;
import com.litt.core.common.Utility;
import com.litt.core.dao.BaseDaoImpl;
import com.litt.core.page.IPageList;
import com.litt.core.page.PagePoParam;

/**
 * <b>标题：</b>字典管理DAO实现.
 * <pre><b>描述</b>
 *    字典管理
 * </pre>
 * 
 * @author lijian
 * @since 2008-5-23
 * @version 1.0
 */
public class DictParamDaoImpl extends BaseDaoImpl implements IDictParamDao {

	/**
	 * 读取字典信息
	 * @param dictId 字典ID
	 * @return TdictParam对象
	 */
	public TdictParam loadById(Long dictId){
		return (TdictParam) super.loadObject(TdictParam.class, dictId);
	}

	/**
	 * 逻辑删除字典信息.
	 * 
	 * @param dictId 字典信息ID
	 */
	public void deleteDictParam(Long dictId){
		TdictParam dictParam = (TdictParam) super.loadObject(TdictParam.class, dictId);
		dictParam.setStatus(new Long(2));
		super.updateObject(dictParam);
	}

	/**
	 * 恢复逻辑删除的字典信息.
	 * 
	 * @param dictId 字典信息ID
	 */
	public void resumeDictParam(Long dictId){
		TdictParam dictParam = (TdictParam) super.loadObject(TdictParam.class, dictId);
		dictParam.setStatus(new Long(0));
		super.updateObject(dictParam);
	}
	
	/**
	 * 保存字典信息.
	 * 
	 * @param dictParam 字典信息对象
	 * @return 主键
	 */
	public Long saveDictParam(TdictParam dictParam){
		return super.saveObject(dictParam);
	}

	/**
	 * 更新字典信息.
	 * 
	 * @param dictParam 字典信息对象
	 */
	public void updateDictParam(TdictParam dictParam){
		super.updateObject(dictParam);
	}
	
	/**
	 * 分页查询参数字典信息.
	 * 
	 * @param pagePoParam 查询参数
	 * @return IPageList IPageList对象
	 */
	public IPageList listByPage(PagePoParam pagePoParam) {
		DictParamPo dictParamPo = (DictParamPo) pagePoParam.getConds();
		StringBuffer listHql = new StringBuffer("from TdictParam where 1=1");
		StringBuffer listCountHql = new StringBuffer("select count(*) from TdictParam where 1=1");
		StringBuffer condition = new StringBuffer ("");
		if(!Utility.isEmpty(dictParamPo.getDictType())){
			System.out.println(dictParamPo.getDictType());
			condition.append(" and dictType like '%");
			condition.append(dictParamPo.getDictType());
			condition.append("%'");
		}
		if(!Utility.isEmpty(dictParamPo.getDictValue())){
			condition.append(" and dictValue like '%");
			condition.append(dictParamPo.getDictValue());
			condition.append("%'");
		}
		
		listHql.append(condition);
		listCountHql.append(condition);
		System.out.println(listHql);
		return super.listHqlPage(listHql.toString(), listCountHql.toString(),pagePoParam.getPageIndex(), pagePoParam.getPageSize());
	
	}


	
}
